package com.kede.app.rest;

import com.kede.annotation.Log;
import com.kede.app.domain.StoreUserOrder;
import com.kede.app.service.StoreUserOrderService;
import com.kede.app.service.dto.StoreUserOrderQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @author Pr.li
* @date 2023-06-10
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "userSupplieLog管理")
@RequestMapping("/api/storeUserOrder")
public class StoreUserOrderController {

    private final StoreUserOrderService storeUserOrderService;

    /**
     * 导出数据
     **/
    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('storeUserOrder:list')")
    public void exportStoreUserOrder(HttpServletResponse response, StoreUserOrderQueryCriteria criteria) throws IOException {
        storeUserOrderService.download(storeUserOrderService.queryAll(criteria), response);
    }

    /**
    * 查询userSupplieLog
    **/
    @GetMapping
    @ApiOperation("查询userSupplieLog")
    @PreAuthorize("@el.check('storeUserOrder:list')")
    public ResponseEntity<Object> queryStoreUserOrder(StoreUserOrderQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(storeUserOrderService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    /**
    * 新增userSupplieLog
    **/
    @PostMapping
    @Log("新增userSupplieLog")
    @ApiOperation("新增userSupplieLog")
    @PreAuthorize("@el.check('storeUserOrder:add')")
    public ResponseEntity<Object> createStoreUserOrder(@Validated @RequestBody StoreUserOrder resources){
        return new ResponseEntity<>(storeUserOrderService.create(resources),HttpStatus.CREATED);
    }


    /**
    * 修改userSupplieLog
    **/
    @PutMapping
    @Log("修改userSupplieLog")
    @ApiOperation("修改userSupplieLog")
    @PreAuthorize("@el.check('storeUserOrder:edit')")
    public ResponseEntity<Object> updateStoreUserOrder(@Validated @RequestBody StoreUserOrder resources){
        storeUserOrderService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }


    /**
    * 删除userSupplieLog
    **/
    @DeleteMapping
    @Log("删除userSupplieLog")
    @ApiOperation("删除userSupplieLog")
    @PreAuthorize("@el.check('storeUserOrder:del')")
    public ResponseEntity<Object> deleteStoreUserOrder(@RequestBody Integer[] ids) {
        storeUserOrderService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}